﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Management;

namespace PRE.Demo
{
    public partial class FrmTestId : DevExpress.XtraEditors.XtraForm
    {
        public FrmTestId()
        {
            InitializeComponent();
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
            //string _cpuID = CpuId();
            //txtCpuId.Text = _cpuID;

            //string _hard = HardDriveId();
            //txtHard.Text = _hard;
            decimal so = Convert.ToDecimal(txtCpuId.Text);
            string kq = ToString(so);
            txtHard.Text = kq;
        }

        private string CpuId()
        {
            string cpuInfo = string.Empty;
            ManagementClass mc = new ManagementClass("win32_processor");
            ManagementObjectCollection moc = mc.GetInstances();

            foreach (ManagementObject mo in moc)
            {
                if (cpuInfo == "")
                {
                    // Lấy về mã số Processor.
                    cpuInfo = mo.Properties["processorID"].Value.ToString();
                    break;
                }
            }
            return cpuInfo;
        }

        private string HardDriveId()
        {
            string serial_number = "";
            ManagementObjectSearcher MOS = new ManagementObjectSearcher("Select * From Win32_DiskDrive");
            foreach (ManagementObject getserial in MOS.Get())

                serial_number = getserial["DiskDriveID"].ToString();

            return serial_number;
            //ManagementObject dsk = new ManagementObject(@"win32_logicaldisk.deviceid=""" + drive + @":""");
            //dsk.Get();
            //string volumeSerial = dsk["VolumeSerialNumber"].ToString();
        }

        private void FrmTestId_Load(object sender, EventArgs e)
        {
          //  if (FrmTestId.ActiveForm == FrmTestId.ActiveForm)
                MPBC.EditValue = true;
                progressBar1.Minimum = 0;
                progressBar1.Maximum = 100;
        }

        public static string ToString(decimal number)
        {
            string s = number.ToString("#");
            string[] so = new string[] { "không", "một", "hai", "ba", "bốn", "năm", "sáu", "bảy", "tám", "chín" };
            string[] hang = new string[] { "", "nghìn", "triệu", "tỷ" };
            int i, j, donvi, chuc, tram;
            string str = " ";
            bool booAm = false;
            decimal decS = 0;
            
            try
            {
                decS = Convert.ToDecimal(s.ToString());
            }
            catch
            {
            }
            if (decS < 0)
            {
                decS = -decS;
                s = decS.ToString();
                booAm = true;
            }
            i = s.Length;
            if (i == 0)
                str = so[0] + str;
            else
            {
                j = 0;
                while (i > 0)
                {
                    donvi = Convert.ToInt32(s.Substring(i - 1, 1));
                    i--;
                    if (i > 0)
                        chuc = Convert.ToInt32(s.Substring(i - 1, 1));
                    else
                        chuc = -1;
                    i--;
                    if (i > 0)
                        tram = Convert.ToInt32(s.Substring(i - 1, 1));
                    else
                        tram = -1;
                    i--;
                    if ((donvi > 0) || (chuc > 0) || (tram > 0) || (j == 3))
                        str = hang[j] + str;
                    j++;
                    if (j > 3) j = 1;
                    if ((donvi == 1) && (chuc > 1))
                        str = "một " + str;
                    else
                    {
                        if ((donvi == 5) && (chuc > 0))
                            str = "lăm " + str;
                        else if (donvi > 0)
                            str = so[donvi] + " " + str;
                    }
                    if (chuc < 0)
                        break;
                    else
                    {
                        if ((chuc == 0) && (donvi > 0)) str = "lẻ " + str;
                        if (chuc == 1) str = "mười " + str;
                        if (chuc > 1) str = so[chuc] + " mươi " + str;
                    }
                    if (tram < 0) break;
                    else
                    {
                        if ((tram > 0) || (chuc > 0) || (donvi > 0)) str = so[tram] + " trăm " + str;
                    }
                    str = " " + str;
                }
            }
            if (booAm) str = "Âm " + str;
            return str + "đồng chẵn";
        }

        private void btn_Click(object sender, EventArgs e)
        {
            ////ProgressBar pBar = new ProgressBar();

            ////pBar.Location = new System.Drawing.Point(20, 20);
            ////pBar.Name = "progressBar1";
            ////pBar.Width = 200;
            ////pBar.Height = 30;
            //int i = 0;
            
            //for (i = 0; i <= 100; i++)
            //{
            //    progressBar1.Value = i;
            //}
            //if (progressBar1.Value == 100)
            //{
            //    FrmMain frm = new FrmMain();
            //    frm.Show();
            //    progressBar1.Value = 0;
            //    progressBar1.Visible = false;
            //   // this.Close();
            //}

            DateTime dt = DateTime.Now;
            DateTime tmp = Convert.ToDateTime(dteTest.EditValue);
            if (tmp > dt)
                MessageBox.Show("Ngày nhập không được lớn hơn ngày hiện tại","Thông báo");
            else
                MessageBox.Show("OK", "Thông báo");
            
        }

        private void btn2_Click(object sender, EventArgs e)
        {
            
            
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
        //    string makhoa = "Khoa02";
        //    string malop = "K02A03";

        //    Dataset.Demo dm = new Dataset.Demo();
        //    Dataset.DemoTableAdapters.tempDemoTableAdapter abc = new Dataset.DemoTableAdapters.tempDemoTableAdapter();
        //    XRDemoReport xr = new XRDemoReport();
        //    xr.DataSource = abc;
        //    xr.DataBingding();

        //    DemoReport dr = new DemoReport();
            
        //    //printControl1.PrintingSystem = xr.PrintingSystem;
        //    xr.CreateDocument();
        //    dr.Show();
        }

        
    }
}
